<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>出错提示页面</title>
    <link rel="stylesheet" href="{{asset('css/bootstrap.min.css')}}">
    <script src="{{asset('js/jquery-3.5.1.min.js')}}"></script>
    <script src="{{asset('js/popper.min.js')}}"></script>
    <script src="{{asset('js/bootstrap.min.js')}}"></script>
    <script src="{{asset('js/layer/layer.js')}}"></script>
    <style>
        html, body{
            height: 100%;
        }
        .error-frame{
            padding-top: 100px;
        }

        .error-content{
            padding: 20px;
            margin: 0 auto;
            width: 400px;
            border: 1px solid #eee;
        }


    </style>
</head>
<body>
<div class="error-frame">
    <div class="error-content" >
        <h2 style="text-align: center;margin-bottom: 20px;">出错提示</h2>
        @if(isset($errorMsg))
            <span>出错原因：{{$errorMsg}}</span>
        @else
            <span>操作出错</span>
        @endif
        , 点击
        @if(isset($errorReturnName) && isset($errorReturnUrl))
            <a href="{{$errorReturnUrl}}">跳转到{{$errorReturnName}}</a>
        @else
            <a href="{{url('admin/index')}}">跳转到后台首页</a>
        @endif

    </div>
</div>

<meta name="csrf-token" content="{{csrf_token()}}">

<script>
    $(document).ready(function(){
        $('.btn-post-from').on('click', function(){
            loginFormAjax();
        });
        $(document).keyup(function(event){
            if(event.keyCode == 13){
                loginFormAjax();
            }
        });
        function loginFormAjax(){
            $('.btn-post-from').attr('disabled', 'true');
            $.ajax({
                url: '{{url('admin/login')}}',
                data: $('#formPost').serialize(),
                dataType: 'json',
                type: 'POST',
                success: function(e){
                    console.log(e);
                    if(e.code == 20000){
                        window.location.href = '{{url('admin/index')}}';
                    } else {
                        layer.msg(e.msg);
                    }
                },
                error: function(e){
                    let errorMessage = e.responseText;
                    errorMessage = errorMessage ? JSON.parse(errorMessage) : [];
                    layer.msg('请30秒后重试');
                },
                complete: function(e){
                    $('.btn-post-from').removeAttr('disabled');
                }
            });
        }
    });

</script>
</body>
</html>